
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>串口的格式化输出 · STM32HAL系列教程</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Atonidas">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-lou/lou.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="串口DMA传输.html" />
    
    
    <link rel="prev" href="串口发送及中断接收.html" />
    

    </head>
    <body>
         

<div class="book">
  <div class="header-inner">
    <!-- LOGO -->
    <div class="logo"></div>
    <span class="title"></span>

    <!-- Search -->
    
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>


    <!-- Nav -->
    <ul class="header-nav">
      <li>
        <a href="https://Gitee.com/atonidas" target="_blank">Gitee</a>
      </li>
    </ul>
  </div>

  <div class="book-summary">
    <div class="book-summary-title">文档目录</div>
     
    <nav role="navigation">


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../软件环境/">
            
                <a href="../软件环境/">
            
                    
                    软件环境
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../软件环境/VScode的使用.html">
            
                <a href="../软件环境/VScode的使用.html">
            
                    
                    VScode快速入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../软件环境/VSCode插件分享.html">
            
                <a href="../软件环境/VSCode插件分享.html">
            
                    
                    VScode插件分享
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../软件环境/CubeMX简介.html">
            
                <a href="../软件环境/CubeMX简介.html">
            
                    
                    CubeMX简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../软件环境/创建一个工程.html">
            
                <a href="../软件环境/创建一个工程.html">
            
                    
                    创建一个工程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../软件环境/Git版本管理.html">
            
                <a href="../软件环境/Git版本管理.html">
            
                    
                    Git版本管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../软件环境/创建一个快速开发模板.html">
            
                <a href="../软件环境/创建一个快速开发模板.html">
            
                    
                    创建一个快速开发模板
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../STM32的IO口/">
            
                <a href="../STM32的IO口/">
            
                    
                    STM32的IO口
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../STM32的IO口/点亮一个LED.html">
            
                <a href="../STM32的IO口/点亮一个LED.html">
            
                    
                    点亮一个LED
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../STM32的IO口/使用独立按键.html">
            
                <a href="../STM32的IO口/使用独立按键.html">
            
                    
                    使用独立按键
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../STM32中断/">
            
                <a href="../STM32中断/">
            
                    
                    STM32中断
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../STM32中断/CubeMX外部中断配置.html">
            
                <a href="../STM32中断/CubeMX外部中断配置.html">
            
                    
                    CubeMX外部中断配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../STM32中断/HAL库外部中断程序.html">
            
                <a href="../STM32中断/HAL库外部中断程序.html">
            
                    
                    HAL库外部中断程序
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../STM32定时器/">
            
                <a href="../STM32定时器/">
            
                    
                    STM32定时器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../STM32定时器/定时器简单中断程序.html">
            
                <a href="../STM32定时器/定时器简单中断程序.html">
            
                    
                    定时器简单中断程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../STM32定时器/硬件PWM输出.html">
            
                <a href="../STM32定时器/硬件PWM输出.html">
            
                    
                    硬件PWM输出
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../STM32定时器/DMA输出PWM控制WS2812.html">
            
                <a href="../STM32定时器/DMA输出PWM控制WS2812.html">
            
                    
                    DMA输出PWM控制WS2812
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="./">
            
                <a href="./">
            
                    
                    STM32串口
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="串口发送及中断接收.html">
            
                <a href="串口发送及中断接收.html">
            
                    
                    串口发送及中断接收
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.2" data-path="串口的格式化输出.html">
            
                <a href="串口的格式化输出.html">
            
                    
                    串口的格式化输出
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="串口DMA传输.html">
            
                <a href="串口DMA传输.html">
            
                    
                    串口DMA传输
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="简单协议编写.html">
            
                <a href="简单协议编写.html">
            
                    
                    简单协议编写
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../SPI协议/">
            
                <a href="../SPI协议/">
            
                    
                    SPI协议
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../SPI协议/CubeMX配置及主要函数.html">
            
                <a href="../SPI协议/CubeMX配置及主要函数.html">
            
                    
                    CubeMX配置及主要参数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../SPI协议/OLED驱动移植.html">
            
                <a href="../SPI协议/OLED驱动移植.html">
            
                    
                    OLED驱动移植
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../SPI协议/LVGL移植显示.html">
            
                <a href="../SPI协议/LVGL移植显示.html">
            
                    
                    LVGL移植显示
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../SPI协议/Flash的使用及文件系统.html">
            
                <a href="../SPI协议/Flash的使用及文件系统.html">
            
                    
                    Flash的使用及文件系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../ADC的使用/">
            
                <a href="../ADC的使用/">
            
                    
                    ADC的使用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../ADC的使用/CubeMX中ADC配置概览.html">
            
                <a href="../ADC的使用/CubeMX中ADC配置概览.html">
            
                    
                    CubeMX中ADC配置概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../ADC的使用/查询阻塞方式.html">
            
                <a href="../ADC的使用/查询阻塞方式.html">
            
                    
                    查询阻塞方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../ADC的使用/中断方式.html">
            
                <a href="../ADC的使用/中断方式.html">
            
                    
                    中断方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../ADC的使用/DMA方式.html">
            
                <a href="../ADC的使用/DMA方式.html">
            
                    
                    DMA方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../ADC的使用/应用示例.html">
            
                <a href="../ADC的使用/应用示例.html">
            
                    
                    应用示例
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../其他代码整合搬运/">
            
                <a href="../其他代码整合搬运/">
            
                    
                    其他代码整合搬运
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../其他代码整合搬运/MultiButton.html">
            
                <a href="../其他代码整合搬运/MultiButton.html">
            
                    
                    MultiButton
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../其他代码整合搬运/EasyLogger.html">
            
                <a href="../其他代码整合搬运/EasyLogger.html">
            
                    
                    EasyLogger
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../其他代码整合搬运/letter-shell.html">
            
                <a href="../其他代码整合搬运/letter-shell.html">
            
                    
                    letter-shell
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../其他代码整合搬运/EasyFlash.html">
            
                <a href="../其他代码整合搬运/EasyFlash.html">
            
                    
                    EasyFlash
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../其他代码整合搬运/时间片调度.html">
            
                <a href="../其他代码整合搬运/时间片调度.html">
            
                    
                    时间片调度
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../加入我们/">
            
                <a href="../加入我们/">
            
                    
                    加入我们
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../加入我们/Gitbook环境.html">
            
                <a href="../加入我们/Gitbook环境.html">
            
                    
                    Gitbook环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../加入我们/Markdown语法简介.html">
            
                <a href="../加入我们/Markdown语法简介.html">
            
                    
                    Markdown语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../加入我们/编辑器推荐.html">
            
                <a href="../加入我们/编辑器推荐.html">
            
                    
                    编辑器推荐
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../加入我们/工程文件说明.html">
            
                <a href="../加入我们/工程文件说明.html">
            
                    
                    工程文件说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../加入我们/提交注意事项.html">
            
                <a href="../加入我们/提交注意事项.html">
            
                    
                    提交注意事项
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>

</nav>
     
  </div>

  <!-- Content nav -->
  <div class="book-anchor">
    <div class="book-anchor-title"></div>

    <div class="book-anchor-body"></div>
  </div>

  <div class="book-body">
    
    <div class="body-inner">
       

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >串口的格式化输出</a>
    </h1>
</div>



      <div class="page-wrapper" tabindex="-1" role="main">
        <div class="page-inner">
          
<div id="book-search-results">
    <div class="search-noresults">
    
          <section class="normal markdown-section">
             <h1 id="printf">Printf</h1>
<h2 id="&#x7A0B;&#x5E8F;&#x6DFB;&#x52A0;">&#x7A0B;&#x5E8F;&#x6DFB;&#x52A0;</h2>
<p>GCC &#x7F16;&#x8BD1;&#x4E0B;&#x548C;&#x5728; MDK &#x4E2D;&#x7684; printf &#x91CD;&#x5B9A;&#x5411;&#x6709;&#x6240;&#x4E0D;&#x540C;&#xFF0C;&#x4EE5;&#x4E0B;&#x4F1A;&#x5206;&#x522B;&#x6F14;&#x793A;</p>
<blockquote>
<p>&#x5F00;&#x59CB;&#x91CD;&#x5B9A;&#x5411;&#x4E4B;&#x524D;&#x8BF7;&#x6253;&#x5F00;&#x4E00;&#x4E2A;&#x53EF;&#x7528;&#x7684;&#x4E32;&#x53E3;&#xFF0C;&#x53EF;&#x4EE5;&#x53C2;&#x8003;&#x524D;&#x9762;&#x6587;&#x7AE0;</p>
</blockquote>
<p>&#x9996;&#x5148;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x6DFB;&#x52A0;&#x5934;&#x6587;&#x4EF6;<code>stdio.h</code>&#xFF0C;&#x53EF;&#x4EE5;&#x653E;&#x5728;<code>usart.c</code>&#x4E2D;&#x7684;&#x5982;&#x4E0B;&#x7684;&#x4F4D;&#x7F6E;&#xFF1A;</p>
<pre><code class="lang-c"><span class="hljs-comment">/* USER CODE BEGIN 0 */</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdio.h&gt;</span></span>
<span class="hljs-comment">/* USER CODE END 0 */</span>
</code></pre>
<p>&#x800C;&#x540E;&#x662F;&#x5728;<code>usart.c</code>&#x4E0B;&#x65B9;&#xFF0C;&#x7F16;&#x5199;&#x5982;&#x4E0B;&#x4EE3;&#x7801;&#xFF0C;&#x5B9E;&#x73B0;&#x5BF9; printf &#x7684;&#x91CD;&#x5B9A;&#x5411;&#xFF1A;</p>
<p>&#x5728; GCC &#x7F16;&#x8BD1;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-c"><span class="hljs-keyword">int</span> _write (<span class="hljs-keyword">int</span> fd, <span class="hljs-keyword">char</span> *pBuffer, <span class="hljs-keyword">int</span> size)
{
    HAL_UART_Transmit(&amp;huart1, pBuffer, size, <span class="hljs-number">0xff</span>);
    <span class="hljs-keyword">return</span> size;
}
</code></pre>
<p>&#x5728;&#x4E00;&#x822C;&#x7684; MDK &#x7F16;&#x8BD1;&#x4E2D;&#xFF1A;</p>
<pre><code class="lang-c"><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">fputc</span><span class="hljs-params">(<span class="hljs-keyword">int</span> ch, FILE *f)</span>
</span>{
  HAL_UART_Transmit(&amp;huart1, (<span class="hljs-keyword">uint8_t</span> *)&amp;ch, <span class="hljs-number">1</span>, <span class="hljs-number">0xffff</span>);
  <span class="hljs-keyword">return</span> ch;
}
</code></pre>
<h2 id="&#x6548;&#x679C;&#x6F14;&#x793A;">&#x6548;&#x679C;&#x6F14;&#x793A;</h2>
<p>&#x4E4B;&#x540E;&#x5728;&#x4E3B;&#x51FD;&#x6570;&#x4E2D;&#x5305;&#x542B;&#x5934;&#x6587;&#x4EF6; stdio.h &#x5373;&#x53EF;printf&#x8F93;&#x51FA;&#xFF1A;</p>
<p><img src="assets/printf&#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;.png" alt=""></p>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF1A;GCC&#x7F16;&#x8BD1;&#x4E0B; printf &#x88AB;&#x4F18;&#x5316;&#xFF0C;<strong>&#x65E0;&#x6CD5;&#x8F93;&#x51FA;&#x6D6E;&#x70B9;&#x6570;</strong>&#xFF0C;&#x53EF;&#x4EE5;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x540E;&#x653E;&#x5927;&#x8F93;&#x51FA;&#xFF1A;</p>
<p><img src="assets/&#x6D6E;&#x70B9;&#x653E;&#x5927;&#x8F93;&#x51FA;.png" alt=""></p>
<h1 id="sprintf">Sprintf</h1>
<blockquote>
<p>&#x6709;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x91CD;&#x5B9A;&#x5411;&#x7684;printf&#x53EA;&#x80FD;&#x5BF9;&#x4E00;&#x4E2A;&#x5916;&#x8BBE;&#x8FDB;&#x884C;&#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;&#xFF0C;&#x4E0D;&#x592A;&#x591F;&#x7528;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6309;&#x7167;&#x5982;&#x4E0B;&#x65B9;&#x5F0F;&#x7F16;&#x5199;&#x81EA;&#x5DF1;&#x7684;&#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;&#x51FD;&#x6570;</p>
</blockquote>
<h2 id="&#x7A0B;&#x5E8F;&#x7F16;&#x5199;">&#x7A0B;&#x5E8F;&#x7F16;&#x5199;</h2>
<p>&#x9700;&#x8981;&#x5305;&#x542B;&#x5982;&#x4E0B;&#x5934;&#x6587;&#x4EF6;&#xFF1A;</p>
<pre><code class="lang-c"><span class="hljs-comment">/* USER CODE BEGIN 0 */</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdio.h&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdarg.h&gt;</span></span>
</code></pre>
<p>&#x540C;&#x6837;&#x5728; usart.c &#x4E2D;&#x7F16;&#x5199;&#x4EE3;&#x7801;&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-c"><span class="hljs-comment">/* USER CODE BEGIN 1 */</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> BUF_SIZE 128</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Uart1_Printf</span><span class="hljs-params">(<span class="hljs-keyword">char</span> *fmt, ...)</span>
</span>{
    <span class="hljs-keyword">uint8_t</span> Uart_Printf_Buf[BUF_SIZE] = {<span class="hljs-number">0</span>};
    va_list args;
    va_start(args, fmt);
    vsnprintf((<span class="hljs-keyword">char</span> *)Uart_Printf_Buf, BUF_SIZE, (<span class="hljs-keyword">char</span> *)fmt, args);
    va_end(args);
    HAL_UART_Transmit(&amp;huart1, Uart_Printf_Buf, BUF_SIZE, <span class="hljs-number">0xff</span>);
}
</code></pre>
<p>&#x5728; usart.h &#x4E2D;&#x58F0;&#x660E;&#x6211;&#x4EEC;&#x5B9A;&#x4E49;&#x7684;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-c"><span class="hljs-comment">/* USER CODE BEGIN Prototypes */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Uart1_Printf</span><span class="hljs-params">(<span class="hljs-keyword">char</span> *fmt, ...)</span></span>;
</code></pre>
<h2 id="&#x6548;&#x679C;&#x6F14;&#x793A;">&#x6548;&#x679C;&#x6F14;&#x793A;</h2>
<p>&#x56E0;&#x4E3A; usart.h &#x5DF2;&#x7ECF;&#x9ED8;&#x8BA4;&#x5728; main.c &#x5305;&#x542B;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x7F16;&#x5199;&#x4EE3;&#x7801;&#x6D4B;&#x8BD5;&#xFF1A;</p>
<p><img src="assets/&#x81EA;&#x5B9A;&#x4E49;&#x6807;&#x51C6;&#x5316;&#x8F93;&#x51FA;.png" alt=""></p>
<h1 id="&#x7B80;&#x7248;elog">&#x7B80;&#x7248;elog</h1>
<blockquote>
<p>&#x90E8;&#x5206;&#x5185;&#x5BB9;&#x53C2;&#x8003;<a href="https://mculover666.blog.csdn.net/article/details/105371993" target="_blank">CSDN&#x535A;&#x5BA2;</a></p>
</blockquote>
<h2 id="&#x7B80;&#x4ECB;">&#x7B80;&#x4ECB;</h2>
<p>elog &#x5168;&#x79F0;EasyLogger&#xFF0C;&#x662F; GitHub &#x4E0A;&#x7684;&#x4E00;&#x4E2A;&#x5F00;&#x6E90;&#x9879;&#x76EE;&#xFF0C;&#x4F5C;&#x8005;armink&#xFF0C;&#x76EE;&#x524D;&#x6536;&#x83B7; 1.1K &#x4E2A; star&#xFF0C;&#x9075;&#x5FAA; MIT &#x5F00;&#x6E90;&#x8BB8;&#x53EF;&#x534F;&#x8BAE;&#xFF0C;&#x53EF;&#x4EE5;&#x653E;&#x5FC3;&#x7528;&#x4E8E;&#x81EA;&#x5DF1;&#x9879;&#x76EE;&#x4E2D;&#x3002;</p>
<p>&#x8FD9;&#x662F;&#x4E00;&#x6B3E;&#x8D85;&#x8F7B;&#x91CF;&#x7EA7;&#x3001;&#x9AD8;&#x6027;&#x80FD;&#x7684; C/C++ &#x65E5;&#x5FD7;&#x5E93;&#xFF0C;&#x975E;&#x5E38;&#x9002;&#x5408;&#x5BF9;&#x8D44;&#x6E90;&#x654F;&#x611F;&#x7684;&#x8F6F;&#x4EF6;&#x9879;&#x76EE;&#xFF0C;&#x76F8;&#x6BD4;&#x4E4B;&#x4E0B;&#xFF0C; EasyLogger &#x7684;&#x529F;&#x80FD;&#x66F4;&#x52A0;&#x7B80;&#x5355;&#xFF0C;&#x63D0;&#x4F9B;&#x7ED9;&#x7528;&#x6237;&#x7684;&#x63A5;&#x53E3;&#x66F4;&#x5C11;&#xFF0C;&#x4E0A;&#x624B;&#x4F1A;&#x66F4;&#x5FEB;&#xFF0C;&#x66F4;&#x591A;&#x5B9E;&#x7528;&#x529F;&#x80FD;&#x652F;&#x6301;&#x4EE5;&#x63D2;&#x4EF6;&#x5F62;&#x5F0F;&#x8FDB;&#x884C;&#x52A8;&#x6001;&#x6269;&#x5C55;&#x3002;</p>
<p>&#x76EE;&#x524D;elog&#x652F;&#x6301;&#x4EE5;&#x4E0B;&#x529F;&#x80FD;&#xFF1A;</p>
<ul>
<li>&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#x65B9;&#x5F0F;&#x652F;&#x6301;&#x4E32;&#x53E3;&#x3001;Flash&#x3001;&#x6587;&#x4EF6;&#x7B49;</li>
<li>&#x65E5;&#x5FD7;&#x5185;&#x5BB9;&#x53EF;&#x5305;&#x542B;&#x7EA7;&#x522B;&#x3001;&#x65F6;&#x95F4;&#x6233;&#x3001;&#x7EBF;&#x7A0B;&#x4FE1;&#x606F;&#x3001;&#x8FDB;&#x7A0B;&#x4FE1;&#x606F;&#x7B49;</li>
<li>&#x652F;&#x6301;&#x591A;&#x79CD;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#xFF0C;&#x652F;&#x6301;&#x88F8;&#x673A;</li>
<li>&#x5404;&#x7EA7;&#x522B;&#x65E5;&#x5FD7;&#x652F;&#x6301;&#x4E0D;&#x540C;&#x989C;&#x8272;&#x663E;&#x793A;</li>
</ul>
<p>&#x56E0;&#x6B64;&#x6559;&#x7A0B;&#x4F5C;&#x8005;&#x6C34;&#x5E73;&#x6709;&#x9650;&#xFF0C;&#x6682;&#x53EA;&#x63D0;&#x4F9B;&#x7B80;&#x5355;&#x7684;&#x3001;&#x53EA;&#x4FDD;&#x7559;&#x57FA;&#x7840;&#x529F;&#x80FD;&#x7684;elog&#x79FB;&#x690D;&#x6559;&#x7A0B;&#xFF0C;&#x5176;&#x4ED6;&#x5185;&#x5BB9;&#x540E;&#x7EED;&#x5355;&#x72EC;&#x66F4;&#x65B0;</p>
<h2 id="&#x4E32;&#x53E3;&#x65B9;&#x5F0F;elog">&#x4E32;&#x53E3;&#x65B9;&#x5F0F;elog</h2>
<h3 id="&#x6587;&#x4EF6;&#x7684;&#x6DFB;&#x52A0;">&#x6587;&#x4EF6;&#x7684;&#x6DFB;&#x52A0;</h3>
<p>&#x76EE;&#x524D;&#x6574;&#x7406;&#x4E86;&#x57FA;&#x7840;&#x529F;&#x80FD;&#x7684;elog&#xFF0C;&#x51E0;&#x4E4E;&#x53EF;&#x4EE5;&#x5F00;&#x7BB1;&#x5373;&#x7528;&#xFF0C;&#x4EE3;&#x7801;&#x4EE5;&#x4E0A;&#x4F20;&#x81F3;<a href="https://wwo.lanzouy.com/ipONizvo42b" target="_blank">&#x7F51;&#x76D8;</a>,&#x4E0B;&#x8F7D;&#x540E;&#x6DFB;&#x52A0;&#x5230;&#x6253;&#x5F00;&#x4E86;&#x4EFB;&#x610F;&#x4E32;&#x53E3;&#x7684;&#x5DE5;&#x7A0B;&#x4E2D;&#xFF1A;</p>
<p><img src="assets/elog&#x6E90;&#x7801;&#x6DFB;&#x52A0;.png" alt=""></p>
<p>&#x5728;&#x4E0A;&#x56FE;&#x4E2D; &#x7684;<code>elog_port.c</code>&#x662F; elog &#x79FB;&#x690D;&#x65F6;&#x9700;&#x8981;&#x5BF9;&#x63A5;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x56FE;&#x4E2D;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x5B8F;&#x51FD;&#x6570;&#x7528;&#x4E8E;&#x5BF9;&#x63A5;</p>
<h3 id="&#x7A0B;&#x5E8F;&#x7F16;&#x5199;">&#x7A0B;&#x5E8F;&#x7F16;&#x5199;</h3>
<p>&#x5728;&#x5B8C;&#x6210;&#x4E86;&#x4E32;&#x53E3;&#x8F93;&#x51FA;&#x7684;&#x57FA;&#x7840;&#x4E0A;&#xFF0C;&#x5728;<code>usart.h</code>&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x5982;&#x4E0B;&#x7684;&#x5B8F;&#x51FD;&#x6570;&#xFF0C;&#x5177;&#x4F53;&#x7528;&#x4E8E;&#x8F93;&#x51FA;&#x7684;&#x5916;&#x8BBE;&#x53EF;&#x4EE5;&#x81EA;&#x884C;&#x66F4;&#x6539;&#xFF1A;</p>
<pre><code class="lang-c"><span class="hljs-comment">/* USER CODE BEGIN Private defines */</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> Uart1_Output(log, size) HAL_UART_Transmit(&amp;huart1, log, size, 0xff)</span>
</code></pre>
<p>&#x5728;&#x4E3B;&#x51FD;&#x6570;&#x4E2D;&#x5305;&#x542B;&#x5934;&#x6587;&#x4EF6;<code>elog.h</code>&#xFF0C;&#x5B8F;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;TAG&#x65B9;&#x4FBF;&#x81EA;&#x5DF1;&#x89C2;&#x5BDF;&#xFF1A;</p>
<pre><code class="lang-c"><span class="hljs-comment">/* USER CODE BEGIN Includes */</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> LOG_TAG <span class="hljs-string">&quot;main.c&quot;</span></span>

<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">&quot;elog.h&quot;</span></span>
</code></pre>
<p>&#x5728;&#x4E32;&#x53E3;&#x521D;&#x59CB;&#x5316;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x8C03;&#x7528;&#x4EE5;&#x4E0B;&#x7684;&#x51FD;&#x6570;&#x521D;&#x59CB;&#x5316;elog&#xFF0C;&#x5373;&#x53EF;&#x4F7F;&#x7528;elog&#x8FDB;&#x884C;&#x65E5;&#x5FD7;&#x7684;&#x8F93;&#x51FA;&#xFF1A;</p>
<pre><code class="lang-c"><span class="hljs-comment">/* USER CODE BEGIN 2 */</span>
  elog_init();
  elog_start();
  <span class="hljs-comment">/* USER CODE END 2 */</span>
</code></pre>
<p>&#x7B80;&#x5355;&#x5E94;&#x7528;&#x5982;&#x4E0B;:</p>
<p><img src="assets/elog&#x65E5;&#x5FD7;&#x8F93;&#x51FA;.png" alt=""></p>
<p><strong>&#x5176;&#x4E2D;&#xFF1A;</strong></p>
<ul>
<li>I &#xFF1A;log&#x7684;&#x7B49;&#x7EA7;&#xFF0C;&#x8BE5;&#x7B49;&#x7EA7;&#x53EF;&#x4EE5;&#x7B5B;&#x9009;&#x8FC7;&#x6EE4;&#x518D;&#x663E;&#x793A;</li>
<li>main.c &#xFF1A; &#x4E3A;&#x81EA;&#x5B9A;&#x4E49;&#x7684;log&#x6807;&#x7B7E;&#xFF0C;&#x65B9;&#x4FBF;&#x89C2;&#x5BDF;&#x65E5;&#x5FD7;&#x5728;&#x90A3;&#x4E2A;&#x51FD;&#x6570;&#x4E2D;&#x8F93;&#x51FA;</li>
<li>[1008] &#xFF1A; &#x4E3A;&#x8F93;&#x51FA;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#xFF0C;&#x5355;&#x4F4D;&#x4E3A;ms&#xFF0C;&#x6B64;&#x7A0B;&#x5E8F;&#x4E2D;&#x4F7F;&#x7528;HAL&#x7684;&#x6EF4;&#x7B54;&#x5B9A;&#x65F6;&#x5668;&#x83B7;&#x5F97;&#x65F6;&#x95F4;</li>
<li>log test &#xFF1A;&#x8FD9;&#x4E2A;&#x662F;&#x81EA;&#x5DF1;&#x8F93;&#x51FA;&#x7684;&#x5185;&#x5BB9;</li>
</ul>
<h3 id="&#x6574;&#x70B9;&#x82B1;&#x6D3B;">&#x6574;&#x70B9;&#x82B1;&#x6D3B;</h3>
<p>elog&#x662F;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x5F69;&#x8272;&#x8F93;&#x51FA;&#x7684;&#xFF0C;&#x9700;&#x8981;&#x4F7F;&#x80FD;&#x5F69;&#x8272;&#x8F93;&#x51FA;&#xFF1A;</p>
<p><img src="assets/&#x4F7F;&#x80FD;&#x5F69;&#x8272;&#x8F93;&#x51FA;.png" alt=""></p>
<p>&#x6548;&#x679C;&#x5982;&#x4E0B;&#xFF1A;</p>
<p><img src="assets/elog&#x5F69;&#x8272;&#x8F93;&#x51FA;.png" alt=""></p>
<p>&#x5404;&#x4E2A;&#x989C;&#x8272;&#x7684;&#x5B9A;&#x4E49;&#x5728;<code>elog_cfg.h</code>&#x4E2D;&#x901A;&#x8FC7;&#x5B9A;&#x4E49;&#x5B9E;&#x73B0;&#xFF1A;</p>
<p><img src="assets/elog&#x5F69;&#x8272;&#x5B9A;&#x4E49;.png" alt=""></p>
<h2 id="usb&#x65B9;&#x5F0F;">USB&#x65B9;&#x5F0F;</h2>
<p>&#x5BF9;&#x4E8E;&#x6709;USB&#x529F;&#x80FD;&#x7684;&#x5355;&#x7247;&#x673A;&#xFF08;F4&#x53CA;&#x4EE5;&#x4E0A;&#xFF09;&#xFF0C;CubeMX&#x53EF;&#x4EE5;&#x5C06;&#x5176;&#x914D;&#x7F6E;&#x4E3A;&#x865A;&#x62DF;&#x4E32;&#x53E3;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x79FB;&#x690D;&#x6620;&#x5C04;elog&#xFF0C;&#x8FD9;&#x91CC;&#x540C;&#x6837;&#x63D0;&#x4F9B;<a href="https://wwo.lanzouy.com/ijpD1zvpv8f" target="_blank">&#x7B80;&#x7248;&#x6E90;&#x7801;</a></p>
<h3 id="cubemx&#x914D;&#x7F6E;">CubeMX&#x914D;&#x7F6E;</h3>
<p>&#x9700;&#x8981;&#x5728;Connectivity&#x4E2D;&#x6253;&#x5F00;USB&#xFF0C;&#x8BBE;&#x7F6E;&#x4E3A;&#x8BBE;&#x5907;&#x6A21;&#x5F0F;&#xFF1A;</p>
<p>&#xFF08;&#x82E5;&#x65F6;&#x949F;&#x6811;&#x62A5;&#x9519;&#xFF0C;&#x70B9;OK&#xFF0C;&#x8BA9;&#x5176;&#x81EA;&#x52A8;&#x8BBE;&#x7F6E;&#x5373;&#x53EF;&#xFF09;</p>
<p><img src="assets/&#x6253;&#x5F00;USB.png" alt=""></p>
<p>&#x5728;Middleware&#x4E2D;&#x6253;&#x5F00;&#x865A;&#x62DF;&#x4E32;&#x53E3;&#x529F;&#x80FD;&#xFF1A;</p>
<p><img src="assets/&#x6253;&#x5F00;&#x865A;&#x62DF;&#x4E32;&#x53E3;.png" alt=""></p>
<h3 id="&#x51FD;&#x6570;&#x6DFB;&#x52A0;">&#x51FD;&#x6570;&#x6DFB;&#x52A0;</h3>
<p>&#x548C;&#x4E32;&#x53E3;&#x7248;&#x672C;&#x4E00;&#x6837;&#xFF0C;&#x6DFB;&#x52A0;&#x76F8;&#x5E94;&#x5934;&#x6587;&#x4EF6;&#x4EE5;&#x53CA;&#x521D;&#x59CB;&#x5316;&#x8BED;&#x53E5;&#x5373;&#x53EF;&#x4F7F;&#x7528;&#xFF0C;&#x8FD9;&#x91CC;&#x4E0D;&#x5728;&#x4E3E;&#x4F8B;</p>
<h2 id="&#x66F4;&#x591A;">&#x66F4;&#x591A;</h2>
<p>&#x540E;&#x7EED;&#x4F1A;&#x7ED9;&#x597D;&#x7528;&#x7684;&#x5F00;&#x6E90;&#x4EE3;&#x7801;&#x5F00;&#x4E00;&#x4E2A;&#x4E13;&#x95E8;&#x7684;&#x7AE0;&#x8282;&#xFF0C;&#x968F;&#x7F18;&#x66F4;&#x65B0;&#xFF0C;&#x5173;&#x4E8E;elog&#x7684;&#x66F4;&#x591A;&#x7528;&#x6CD5;&#x53EF;&#x4EE5;&#x53C2;&#x8003;CSDN&#x535A;&#x5BA2;&#x548C;github&#xFF1A;</p>
<p>CSDN&#xFF1A;<a href="https://mculover666.blog.csdn.net/article/details/105371993" target="_blank">https://mculover666.blog.csdn.net/article/details/105371993</a></p>
<p>gtihub:<a href="https://github.com/armink/EasyLogger" target="_blank">https://github.com/armink/EasyLogger</a></p>
 
          </section>
          
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>
 
        </div>
      </div>
      
    </div>

     
    <a
      href="串口发送及中断接收.html"
      class="
        navigation navigation-prev
        
      "
      aria-label="Previous page: 串口发送及中断接收"
    >
      <i class="fa fa-angle-left"></i>
    </a>
     
    <a
      href="串口DMA传输.html"
      class="
        navigation navigation-next
        
      "
      aria-label="Next page: 串口DMA传输"
    >
      <i class="fa fa-angle-right"></i>
    </a>
      
  </div>
  <script>
    function showModal() {
      document.getElementsByClassName("mask")[0].style.display = "block";
      document.getElementsByClassName("donate-modal")[0].style.display =
        "block";
    }
    // 切换赞赏码
    function showDonateImg(num) {
      let alipay = "";
      let wxpay = ""
      if(num){
        wxpay = "hidden"
      }else{
        alipay = "hidden"
      }
      document.getElementById("wxpay-code").hidden = wxpay;
      document.getElementById("alipay-code").hidden = alipay;
      document.getElementsByName("pay-way")[num].checked = "checked";
    }

    // 关闭赞赏框
    function closeDonateModal() {
      document.getElementsByClassName("mask")[0].style.display = "none";
      document.getElementsByClassName("donate-modal")[0].style.display = "none";
    }

    var gitbook = gitbook || [];
    gitbook.push(function () {
      gitbook.page.hasChanged({"page":{"title":"串口的格式化输出","level":"1.6.2","depth":2,"next":{"title":"串口DMA传输","level":"1.6.3","depth":2,"path":"STM32串口/串口DMA传输.md","ref":"./STM32串口/串口DMA传输.md","articles":[]},"previous":{"title":"串口发送及中断接收","level":"1.6.1","depth":2,"path":"STM32串口/串口发送及中断接收.md","ref":"./STM32串口/串口发送及中断接收.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-sharing","-search","-favicon","-code","expandable-chapters","theme-lou","back-to-top-button","search-pro","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"livereload":{},"search-pro":{},"code":{"copyButtons":true},"theme-lou":{"hide-elements":[".summary .gitbook-link"],"color":"#8abcd1","copyright":{"author":"Atonidas"},"forbidCopy":false,"logo":"assets/logo.png","search-placeholder":"查找关键内容","copyrightLogo":"assets/copyright.png","favicon":"assets/favicon.ico","autoNumber":3},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"back-to-top-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"Atonidas","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"themeLou":{"nav":[{"target":"_blank","url":"https://Gitee.com/atonidas","name":"Gitee"}]}},"title":"STM32HAL系列教程","gitbook":"*","description":"Gitbook电子书示例项目"},"file":{"path":"STM32串口/串口的格式化输出.md","mtime":"2023-04-04T06:18:13.072Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-09-13T00:50:24.020Z"},"basePath":"..","book":{"language":""}});
    });
  </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-lou/lou.js"></script>
        
    

    </body>
</html>

